import React, { Component } from "react";

import PropTypes from "prop-types"

export default class TabCnntrol extends Component {
  constructor(props) {
    super(props)
    console.log('props---', props);
    this.state = {
      currentIndex: 0,
      currenTitle: null,
    }
  }
  render() {
    const { titles } = this.props
    const { currentIndex } = this.state
    return (
      <div className="tab-control">
        {
          titles.map((item, index) => {
            return <div key={item}
              className={"tab-item " + (index === currentIndex ? "active" : "")}
              onClick={e => this.itemClick(index)}>
              <span>{item}</span>
            </div>
          })
        }
      </div >
    )
  }
  itemClick(index) {
    console.log('1111');
    this.setState({
      currentIndex: index
    })
    let { itemClick } = this.props
    itemClick(index)
  }
}